\section{Basic Math Manipulation}

In this video, we are going to talk about the basics of using mathematical symbols in \LaTeX. Up to this point, we've been working strictly with text. And if the only thing you were doing was creating a text document, there would very little reason for you to use \LaTeX. The real beauty and power of \LaTeX{} is the ability to handle mathematical notation.

The first concept that we need to talk about is math mode. Math mode is just another environment with rules for how to typeset symbols. There are two types of math modes. We can either use the \textit{display style} math mode or the \textit{inline} or \textit{text style} math mode.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-1}}
\end{center}

Display style math mode is intended to be used when mathematical expressions or equations are meant to stand apart from the rest of the text. In other words, we are putting the math on display. This is often used for longer expressions and equations that are being manipulated. Inline math mode keeps the mathematical notation as part of the text of the paragraph. It exists in the line of text.

Let's focus on display mode first. Display mode always breaks out of paragraphs and is always centered. Sometimes the equations are numbered, and sometimes they are not. There are two basic ways to create a display style equation. The first is to use the backslash-bracket combinations. This is best used when you have just a single line of mathematical text to display.

Another way is to use a display math environment, such as the \texttt{align*} environment. The \texttt{align*} environment is specifically designed so that your equal signs would be lined up if you have a set of related equations or expressions. The ampersand symbol tells \LaTeX{} where you want your alignment point to be, and the double backslash tells it to create a new line. You can also use this to align multiple sets of equations by using more ampersands.

The star for this environment simply means that these equations will not be numbered. If you remove the star and use the \texttt{align} environment instead, the equations will be automatically numbered. You can skip the numbering on a specific line by using the \verb|\nonumber| command before [the end of] that line.

This example also shows an organizational trick that you can use. When you're working in math mode, you can use whatever whitespace you want to keep your equations organized and legible. The precise way you organize your code is up to you, but it is good to think about indenting and aligning text to make it easy to read.

For inline math mode, there are two methods you can use. You can either use dollar signs to toggle math mode on and off, or you can use the backslash-parenthesis combinations. The dollar sign method is a slightly dated way of doing it, but it is still very common. But if you're just learning \LaTeX{} now, the backslash-parenthesis is probably a better habit to get into. Ultimately, it makes very little difference.

Whenever you are talking about a mathematical variable, you should be in inline math mode. Notice that your variables are italicized in math mode. The reason for this is that it helps to visually distinguish it as a mathematical variable and not just a letter of the alphabet.

Aside from the placement of the text, inline and display style mathematics are presented differently. Here is an example of the same sum presented in each form. Don't worry about trying to understand all of the notation right now. Just focus on the output. The display style mode is larger and the notation is stacked more vertically, while the inline mode is smaller and stacked more horizontally. You can also see that the fractions are sized differently.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-2}}
\end{center}

There is an aesthetic difference when this is placed inside of a paragraph. The display style notation can create spaces between the lines that can sometimes look awkward. But if you really wanted to use display style text inside of a paragraph, you can force \LaTeX{} to use display style by typing \verb|\displaystyle| immediately after entering into inline math mode. If you wanted to force inline math mode, use would use \verb|\textstyle|.

You will notice in this example that there are a lot of curly brackets. There brackets are used as grouping symbols in the same way that we used them for text sizing. This simply lets \LaTeX{} know that we want the entire collection of symbols inside to be treated as a single unit.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-3}}
\end{center}

We will now move on to look at the mathematical notation itself. Remember that this must always be inside of math mode. We will first look at the four basic functions. For addition and subtraction, you simply use the standard + and – keys on the keyboard. For multiplication, you do not want to use the asterisk. Instead, you would use either \verb|\cdot| to make the multiplication dot or \verb|\times| if want to have the big X notation for multiplication.

The division sign can be created using \verb|\div|, but you should be cautious in your use of this because it can lead to unfortunate and misleading notation. It is usually better to use fractions. To create a fraction in math mode, use \verb|\frac{}{}|, where the contents of the first brackets go in the numerator and the contents of the second brackets in the denominator. The \verb|\frac| notation will let \LaTeX{} pick the size of the fraction based on the context, but you can use either \verb|\dfrac| or \verb|\tfrac| to force \LaTeX{} to use either the display style or inline style fractions.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-4}}
\end{center}

Another important aspect of mathematical notation is the use of superscript and subscript notation. This is when we have small text written either above or below the normal level of text. We can create a superscript by using a caret symbol and a subscript is created using an underscore. It is very important that if your superscript or subscript contains more than one symbol that you encompass it inside of brackets, otherwise the typesetting will come out incorrectly.

If you have both subscripts and superscripts, they will be placed relative to the main character and not each other. This means that the order doesn't matter when \LaTeX{} goes to typeset it. However, there is usually a logical order based on the mathematical language.

You also have the ability of stacking superscripts and subscripts together for more complex notation. You can impact exactly how this looks by using brackets to group different parts together. But these are stylistic choices that you can make for yourself.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-5}}
\end{center}

You can use the standard parentheses and square brackets that are available on the keyboard, but they can sometimes be the wrong size for the application. You can let \LaTeX{} choose the size of your brackets by using \verb|\left| and \verb|\right| with your brackets, or you can manually choose the size using one of these four modifiers. A word of warning if you use \verb|\left| and \verb|\right|: These must always come in pairs so that \LaTeX{} can calculate the height it needs to use. If you only need a symbol on one side or the other for some reason, you can create a blank symbol by using \verb|\left.| or \verb|\right.|.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-6}}
\end{center}

If you want to write text in the middle of math mode, you cannot simply type the text. \LaTeX{} will interpret the whole thing as a product of variables. Instead, you need to use the \verb|\text{}| command. You will need to put an explicit space at the beginning and end of the text because otherwise the letters will be placed directly next to the last mathematical symbol. It can be helpful to organize your statement in a logical manner. In this case, there is an equation and a condition, and so it makes more sense to treat the condition itself as a single text object. Although the output is the same, the code is simpler and easier to read.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-7}}
\end{center}

Another important set of symbols are the Greek letters. Greek letters are available in math mode, and can usually be created using a backslash followed by the name of the letter. Here is the full Greek alphabet. You will notice that there are some Greek letters don't have a special command. This is because the Greek letter is the same as a letter we currently use, and so no new symbol was created. You will also see that there are a few lower case letters with multiple forms. These variants are created by adding \texttt{var} in front of the Greek letter.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-3-8}}
\end{center}

Lastly, mathematicians often want to use a blackboard style font. These are letters that have a double line somewhere in it, such as the $\mathbb{Z}$ used for the integers. The \href{http://texdoc.net/texmf-dist/doc/fonts/amsfonts/amssymb.pdf}{\texttt{amssymb}} package has a set of these symbols for each capital letter, and they're called by using the \verb|\mathbb{}| command.

Of course, there are many pieces of mathematical notation that are not covered in this video. We will see several more types of notation in the next few videos, including one where we focus solely on the notation used in calculus. 